<?php

/**********************************************************************
Copyright (C) FrontAccounting, LLC.
Released under the terms of the GNU General Public License, GPL, 
as published by the Free Software Foundation, either version 3 
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security='SA_GLANALYTIC';

// ----------------------------------------------------------------
// $ Revision:    2.0 $
// Creator:    Joe Hunt
// date_:    2005-05-19
// Title:    List of Journal Entries
// ----------------------------------------------------------------
$path_to_root ="..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/gl/includes/gl_db.inc");
include_once($path_to_root . "/includes/ui/ui_view.inc");
include_once($path_to_root . "/gl/includes/db/gl_db_accounts.inc");
include_once($path_to_root . "/admin/db/fiscalyears_db.inc");

//----------------------------------------------------------------------------------------------------

print_list_of_journal_entries();

//----------------------------------------------------------------------------------------------------

function print_list_of_journal_entries()
    {
    global $path_to_root, $systypes_array;

    $start_month=$_POST['PARAM_0'];
    $end_month  =$_POST['PARAM_1'];

    if ($start_month > $end_month)
        {
        $end_month=$start_month;
        }

    $str=get_current_fiscalyear();    
    $year=0;
    
    if (($timestamp=strtotime($str['begin'])) !== false)
    {$year=date("Y", $timestamp);}
    else{
        display_error('invalid timestamp!');}                                                                        
    $estimasi=input_num('PARAM_2');
    $comments=null;
    
    include_once($path_to_root . "/reporting/includes/excel_report.inc");
    //    else
    //        include_once($path_to_root . "/reporting/includes/pdf_report.inc");

    $dec=user_price_dec();
    $cols=array(0,100,200,300);
    $headers=array('','','');
    $aligns=array('left','left','center');    
    $counter_cols = 300;
    
    $counter = $start_month;   
    while($counter <= $end_month){        
    $counter_cols += 100;
    $cols[] = $counter_cols;
    $counter_cols += 100;
    $cols[] = $counter_cols;
    
    $headers[] = date('F Y', mktime(0, 0, 0, $counter, 1, $year));
    $headers[] = '% dr Pjl';
    
    $aligns[] = 'right';
    $aligns[] = 'right';
    $counter++;
    }
    
    $first   =date('d/m/Y', mktime(0, 0, 0, $start_month, 1, $year));
    $last    =date('t/m/Y', mktime(0, 0, 0, $end_month, 1, $year));
    
    $from    =$first;
    $to      =$last;    
    
    $counter_cols += 100;
    $cols[] = $counter_cols;
    $counter_cols += 100;
    $cols[] = $counter_cols;
    $headers[] = 'Sampai dgn ' . date('F Y', mktime(0, 0, 0, $end_month, 1, $year));
    $headers[] = '% dr Pjl';    
    $aligns[] = 'right';
    $aligns[] = 'right';
    
    
    
    $params=array
        (
        0 => $comments,
        1 => array
            (
            'text' => 'Periode',
            'from' => $from,
            'to'   => $to
            )
        );

    $from=add_days($from, -1);
    $to  =add_days($to, 1);
    $from_aku    =$from;
    $to_aku      =$to; 
    $rep =new FrontReport('Laporan Laba Rugi', "LaporanLabaRugi", user_pagesize());

    $rep->formatHeaderLeft->setBottom(0);
    $rep->formatHeaderRight->setBottom(0);
    $rep->SetHeaderType('Header4');
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
       
    $total_laba_kotor=0.0;
        $penjualan=0.0;
        $return_penjualan=0.0;
        $hpp=0.0;
        $hpp_details=0.0;
        $total_laba_bersih=0.0;
    
    $rep->TextCol(0, 1, "Penjualan");   
    $penjualan_tunai_kaos = array();                             
    $penjualan = array();
    $penjualan_selain_kaos= array();
    $penjualan_pesanan =array();
    $total_penghasilan_lain = array();
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {          
        $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
        $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
        $from    =$first;
        $to      =$last;
        $from=add_days($from, -1);
        $to  =add_days($to, 1);
        $penjualan[] = 0;
        $penjualan_tunai_kaos[] = 0;
        $penjualan_selain_kaos[] = 0;
        $penjualan_pesanan[] = 0;
        $total_penghasilan_lain[] = 0;
        $penjualan_tunai_kaos[$counter_for] = -(get_gl_balance_from_to($from, $to, '41100', 0, 0));
        $penjualan[$counter_for] += $penjualan_tunai_kaos[$counter_for];
        $penjualan_selain_kaos[$counter_for] = -(get_gl_balance_from_to($from, $to, '41200', 0, 0));
        $penjualan[$counter_for] += $penjualan_selain_kaos[$counter_for];
        $penjualan_pesanan[$counter_for] = -(get_gl_balance_from_to($from, $to, '41300', 0, 0));
        $penjualan[$counter_for] += $penjualan_pesanan[$counter_for];
        $total_penghasilan_lain[$counter_for] =-(get_gl_balance_from_to($from, $to, '41900', 0, 0));
        $penjualan[$counter_for] += $total_penghasilan_lain[$counter_for];
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan[$counter_for] / $penjualan[$counter_for]) * 100, 1);
        $counter_for++;
    } 
    $penjualan_distro_aku = -(get_gl_balance_from_to($from_aku, $to_aku, '41100', 0, 0));    
    $penjualan_tunai_selain_kaos_aku = -(get_gl_balance_from_to($from_aku, $to_aku, '41200', 0, 0));
    $penjualan_pesanan_aku = -(get_gl_balance_from_to($from_aku, $to_aku, '41300', 0, 0));
    $penghasilan_lain_aku = -(get_gl_balance_from_to($from_aku, $to_aku, '41900', 0, 0));
    $total_penjualan_aku = $penjualan_distro_aku + $penjualan_tunai_selain_kaos_aku + $penjualan_pesanan_aku + $penghasilan_lain_aku;
    $penjualan_persen_aku = ($total_penjualan_aku / $total_penjualan_aku) * 100;
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_penjualan_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), $penjualan_persen_aku, 1);
    $rep->NewLine();    

    $rep->TextCol(1, 2, get_gl_account_name('41100'));
    $rep->TextCol(2, 3, '41100');     
    
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_tunai_kaos[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_tunai_kaos[$counter_for] / $penjualan[$counter_for]) * 100, 1);
        $counter_for++;
    }       
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_distro_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_distro_aku / $total_penjualan_aku) * 100, 1);                                               
    $rep->NewLine();                                   
    $rep->TextCol(1, 2, get_gl_account_name('41200'));                     
    $rep->TextCol(2, 3, '41200');                      
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_selain_kaos[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_selain_kaos[$counter_for] / $penjualan[$counter_for]) * 100, 1);     
        $counter_for++;
    }                                              
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_tunai_selain_kaos_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_tunai_selain_kaos_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();                                
    $rep->TextCol(1, 2, get_gl_account_name('41300'));
    $rep->TextCol(2, 3, '41300');    
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_pesanan[$counter_for], 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_pesanan[$counter_for] / $penjualan[$counter_for]) * 100, 1);     
        $counter_for++;
    }                                                                       
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_pesanan_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_pesanan_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();                                    
    $rep->TextCol(1, 2, get_gl_account_name('41900'));
    $rep->TextCol(2, 3, '41900');
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_penghasilan_lain[$counter_for], 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_penghasilan_lain[$counter_for] / $penjualan[$counter_for]) * 100, 1); 
        $counter_for++;
    }                                                                           
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penghasilan_lain_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penghasilan_lain_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();               
    $return_penjualan = array();    
    $rep->TextCol(0, 1, "Retur Penjualan");
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {          
        $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
        $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
        $from    =$first;
        $to      =$last;
        $from=add_days($from, -1);
        $to  =add_days($to, 1);
        $return_penjualan[] = 0;
        $return_penjualan[$counter_for]=get_gl_balance_from_to($from, $to, '42100', 0, 0) + get_gl_balance_from_to($from, $to, '42200', 0, 0) + 
        get_gl_balance_from_to($from, $to, '42300', 0, 0);    
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $return_penjualan[$counter_for],0 );
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($return_penjualan[$counter_for] / $penjualan[$counter_for]) * 100, 1);    
        $counter_for++;
    } 
    $return_penjualan_aku = get_gl_balance_from_to($from_aku, $to_aku, '42100', 0, 0) + get_gl_balance_from_to($from_aku, $to_aku, '42200', 0, 0) + 
        get_gl_balance_from_to($from_aku, $to_aku, '42300', 0, 0);    
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $return_penjualan_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($return_penjualan_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();
    
    $rep->TextCol(1, 2, "Penjualan Bersih");
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $penjualan_bersih[$counter_for] = $penjualan[$counter_for] - $return_penjualan[$counter_for];
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_bersih[$counter_for],0 );
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_bersih[$counter_for] / $penjualan[$counter_for]) * 100, 1); 
        $counter_for++;
    }     
    $penjualan_bersih_aku = $total_penjualan_aku - $return_penjualan_aku;
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $penjualan_bersih_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($penjualan_bersih_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();

    $rep->NewLine();
    $format = & $rep->addFormat();
    $format->setBold();
    $format->setAlign('left');
    $format->setAlign('vcenter');
    $rep->TextColExt(0, 1, 'Harga Pokok Penjualan',$format);
    $rep->NewLine();                                                           
    $rep->TextCol(1, 2, get_gl_account_name('51000'));
    $rep->TextCol(2, 3, '51000');
    $hpp_tunai_kaos = array();
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
    $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
        $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
        $from    =$first;
        $to      =$last;
        $from=add_days($from, -1);
        $to  =add_days($to, 1);    
    $hpp_tunai_kaos[] = 0;            
    $hpp_tunai_kaos[$counter_for] = get_gl_balance_from_to($from, $to, '51000', 0, 0);
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $hpp_tunai_kaos[$counter_for], 0);   
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($hpp_tunai_kaos[$counter_for] / $penjualan[$counter_for]) * 100, 1);      
        $counter_for++;
    }
    $hpp_tunai_kaos_aku = get_gl_balance_from_to($from_aku, $to_aku, '51000', 0, 0);
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $hpp_tunai_kaos_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($hpp_tunai_kaos_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();
    $rep->TextCol(1, 2, get_gl_account_name('52000'));
    $rep->TextCol(2, 3, '52000');
    $hpp_penj_pesanan = array();    
    $hpp_selain_kaos = array();
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
        $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
        $from    =$first;
        $to      =$last;
        $from=add_days($from, -1);
        $to  =add_days($to, 1); 
        $hpp_selain_kaos[] = 0;
        $hpp_penj_pesanan[] = 0;
        $hpp_selain_kaos[$counter_for] = get_gl_balance_from_to($from, $to, '52000', 0, 0);
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $hpp_selain_kaos[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($hpp_selain_kaos[$counter_for] / $penjualan[$counter_for]) * 100, 1);
        $counter_for++;
    }
    $hpp_selain_kaos_aku = get_gl_balance_from_to($from_aku, $to_aku, '52000', 0, 0);
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $hpp_selain_kaos_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($hpp_selain_kaos_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();                
    $hpp_account = get_gl_hpp_details();                                   
    $hpp_penj_pesanan_aku = 0;
    while ($myrow = db_fetch($hpp_account))
    {                           
        $rep->TextCol(1,2, get_gl_account_name($myrow['account_code']));
        $rep->TextCol(2, 3, $myrow['account_code']);    
        $counter_for = 0;        
        for($i=$start_month;$i<=$end_month;$i++)    {                                                   
            $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
            $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
            $from    =$first;
            $to      =$last;
            $from=add_days($from, -1);
            $to  =add_days($to, 1);             
            $hpp_details = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0, 0);
            $hpp_penj_pesanan[$counter_for] += $hpp_details;            
            $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $hpp_details, 0);
            $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($hpp_details / $penjualan[$counter_for]) * 100, 1);
            $counter_for++;
        }
        $hpp_details_aku = get_gl_balance_from_to($from_aku, $to_aku, $myrow['account_code'], 0, 0);
        $hpp_penj_pesanan_aku += $hpp_details_aku;            
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $hpp_details_aku, 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($hpp_details_aku / $total_penjualan_aku) * 100, 1);     
        $rep->NewLine();
    } 
    $rep->TextCol(0, 1, 'Harga Pokok Penjualan');
    $total_harga_pokok = array();
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $total_harga_pokok[] = 0;
        $total_harga_pokok[$counter_for] =  $hpp_tunai_kaos[$counter_for] + $hpp_selain_kaos[$counter_for] + $hpp_penj_pesanan[$counter_for];                      
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_harga_pokok[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_harga_pokok[$counter_for] / $penjualan[$counter_for]) * 100, 1);     
        $counter_for++;
    }   
    $total_harga_pokok_aku =  $hpp_tunai_kaos_aku + $hpp_selain_kaos_aku + $hpp_penj_pesanan_aku;                      
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_harga_pokok_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_harga_pokok_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();    
    $rep->TextCol(1, 2, 'Laba Kotor');
    $total_laba_kotor = array();
    $total_beban_pemasaran = array();
    $counter_for = 0;    
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $total_laba_kotor[] = 0;
        $total_beban_pemasaran[] = 0;
        $total_laba_kotor[$counter_for] = $penjualan_bersih[$counter_for] - $total_harga_pokok[$counter_for];
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_laba_kotor[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_laba_kotor[$counter_for] / $penjualan[$counter_for]) * 100, 1);
    $counter_for++;
    }   
    $total_laba_kotor_aku = $penjualan_bersih_aku - $total_harga_pokok_aku;
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_laba_kotor_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_laba_kotor_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();
    $rep->NewLine();                 
    $beban_pemasaran_account = get_gl_beban_pemasaran();
    $total_beban_pemasaran_aku = 0;
    while ($myrow = db_fetch($beban_pemasaran_account))
    {    
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $counter_for = 0;    
        for($i=$start_month;$i<=$end_month;$i++)    {  
            $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
            $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
            $from    =$first;
            $to      =$last;
            $from=add_days($from, -1);
            $to  =add_days($to, 1);             
            $beban_pemasaran = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0,0);
            $total_beban_pemasaran[$counter_for] += $beban_pemasaran;
            $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $beban_pemasaran, 0);
            $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($beban_pemasaran / $penjualan[$counter_for]) * 100, 1);
        $counter_for++;
        }
        $beban_pemasaran_aku = get_gl_balance_from_to($from_aku, $to_aku, $myrow['account_code'], 0,0);
        $total_beban_pemasaran_aku += $beban_pemasaran_aku;
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $beban_pemasaran_aku, 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($beban_pemasaran_aku / $total_penjualan_aku) * 100, 1);     
        $rep->NewLine();
    }
    $rep->TextCol(1, 2, 'Total Beban Pemasaran');
    $total_beban_adm_umum = array();
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {  
        $total_beban_adm_umum[] = 0;
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_beban_pemasaran[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_beban_pemasaran[$counter_for] / $penjualan[$counter_for]) * 100, 1);
        $counter_for++;
    }                     
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_beban_pemasaran_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_beban_pemasaran_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();
    $rep->NewLine();                    
    $beban_adm_umum_account = get_gl_beban_adm_umum();
    $total_beban_adm_umum_aku  = 0;
    while ($myrow = db_fetch($beban_adm_umum_account))
    {           
        $rep->TextCol(0, 1, get_gl_account_name($myrow['account_code']));
        $counter_for = 0;    
        for($i=$start_month;$i<=$end_month;$i++)    {  
            $first   =date('d/m/Y', mktime(0, 0, 0, $i, 1, $year));
            $last    =date('t/m/Y', mktime(0, 0, 0, $i, 1, $year));    
            $from    =$first;
            $to      =$last;
            $from=add_days($from, -1);
            $to  =add_days($to, 1);             
            $beban_adm_umum = get_gl_balance_from_to($from, $to, $myrow['account_code'], 0,0);
            $total_beban_adm_umum[$counter_for] += $beban_adm_umum;
            $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $beban_adm_umum, 0);
            $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($beban_adm_umum  / $penjualan[$counter_for]) * 100, 1);
            $counter_for++;
        }
        $beban_adm_umum_aku = get_gl_balance_from_to($from_aku, $to_aku, $myrow['account_code'], 0,0);
        $total_beban_adm_umum_aku += $beban_adm_umum_aku;
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $beban_adm_umum_aku, 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($beban_adm_umum_aku / $total_penjualan_aku) * 100, 1);     
        $rep->NewLine();
    }
    $rep->TextCol(1, 2, 'Total Beban Administrasi dan Umum');
    $counter_for = 0;
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $total_beban_adm_umum[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($total_beban_adm_umum[$counter_for] / $penjualan[$counter_for]) * 100, 1); 
        $counter_for++;
    }
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $beban_adm_umum_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($beban_adm_umum_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();
    $rep->NewLine();                                                          
    $rep->TextCol(0, 1, 'Laba Bersih');
    $laba_bersih = array();
    $counter_for = 0;
    
    for($i=$start_month;$i<=$end_month;$i++)    {                                                   
        $laba_bersih[] = 0;
        $laba_bersih[$counter_for] = $total_laba_kotor[$counter_for] - $total_beban_pemasaran[$counter_for] - $total_beban_adm_umum[$counter_for];        
        $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $laba_bersih[$counter_for], 0);
        $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($laba_bersih[$counter_for] / $penjualan[$counter_for]) * 100, 1);     
        $counter_for++;
    }
    $laba_bersih_aku = $total_laba_kotor_aku - $total_beban_pemasaran_aku - $total_beban_adm_umum_aku;        
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $laba_bersih_aku, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($laba_bersih_aku / $total_penjualan_aku) * 100, 1);     
    $rep->NewLine();
  
    $date = date_create(date2sql(add_days($to_aku, -1)));        
    $rep->TextCol(0, 1, 'Estimasi Persediaan Bahan Baku Per '.date_format($date, 'd F Y'));
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $estimasi, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($estimasi / $total_penjualan_aku) * 100, 1);
    $rep->NewLine();
    
    $laba_bersih_setelah_penyesuaian = $laba_bersih_aku + $estimasi;
    $rep->TextCol(0, 1, 'Laba Bersih Setelah Penyesuaian Stok Akhir');
    $rep->AmountCol(3+($counter_for*2), 4+($counter_for*2), $laba_bersih_setelah_penyesuaian, 0);
    $rep->PercentCol(4+($counter_for*2), 5+($counter_for*2), ($laba_bersih_setelah_penyesuaian / $total_penjualan_aku) * 100, 1);
    
    $rep->End();
    }
?>
